﻿using System;
using System.Collections.Generic;
using System.Net;

namespace Toybox.NicoSharp.Video.RiApi
{
	using Extensions;
	using RiApiPrimitives;
	using Utilities;

	public class Search : AbstractSearch
	{

		#region [Static]

		public static Search Get(string words, VideoSortType sortType = VideoSortType.CommentDate, OrderType orderType = OrderType.Desc, int page = 1, CookieCollection cookies = null)
		{
			if (string.IsNullOrEmpty(words)) return null;

			string url = NicoUrls.RiApi + "search/search";

			Dictionary<string, string> query = new Dictionary<string, string>();

			// なぜか２回
			words = Uri.EscapeUriString(Uri.EscapeUriString(words));
			query.Add("words", words);
			// mode? 動画とか静画とか？
			query.Add("mode", "watch");
			query.Add("order", orderType == OrderType.Desc ? "d" : "a");
			query.Add("page", page.ToString());
			query.Add("sort", sortType.ToSign());

			return Get<Search>(url + "?" + Serializer.AndEqualPairSerializer(query), cookies);
		}

		#endregion [Static]

	}
}
